package com.hnkywl.sts.action.cggl;

import com.hnkywl.sts.dao.cggl.CgdmxDao;
import com.hnkywl.sts.entity.sys.Gncz;
import com.hnkywl.sts.service.cggl.CgdmxService;
import com.hnkywl.sts.service.sys.GnczService;
import com.hnkywl.sts.util.POIUtil;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.Region;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: lenovo
 * Date: 13-4-30
 * Time: 上午11:34
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/cggl/cgmx")
public class CgmxAction extends SimpleActionSupport {
    private CgdmxService cgdmxService;
    private CgdmxDao cgdmxDao;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows;
    //行索引
    private int index;
    //查询条件
    private String cgdh;
    private Long gysId;
    private String gysJc;
    private Long ckId;
    private String code;
    private String name;
    private String ggxh;
    private Long sbgsId;
    private Long sbbmId;
    private String zt;

    private Date CurrentTime = new Date();

    //开始时间
    private Date fhrqStart;
    //结束时间
    private Date fhrqEnd;
    //功能操作
    private List<Gncz> gnczList;
    private GnczService gnczService;

    private Long[] cgdmxIds;

    @Action("cgmx")
    public String cgmx() {
        gnczList = gnczService.findGnczByJsAndUrl(request.getServletPath());
        return SUCCESS;
    }

    //采购明细列表
    @Action("cgmxList")
    public void cgmxList() {
        try {
            this.renderJson(this.cgdmxService.findCgmxList(cgdh, gysId, ckId, code, name, ggxh, sbgsId, sbbmId, zt, fhrqStart, fhrqEnd, page, rows));
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Action("cgmx_export")
    public String cgmxExport() {
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
        List<Map> cgmxList = this.cgdmxDao.findCgdmxList(cgdh, gysId, ckId, code, name, ggxh, sbgsId, sbbmId, zt, fhrqStart, fhrqEnd);
        //第一步，创建一个webbook，对应一个Excel文件
        HSSFWorkbook wb = new HSSFWorkbook();
        //第二步，在webbook中添加一个sheet,对应Excel文件中的sheet
        HSSFSheet sheet = wb.createSheet("采购明细");
        POIUtil poiUtil = new POIUtil(wb);
        //设置列宽
        sheet.setDefaultRowHeightInPoints(14);
        sheet.setDefaultColumnWidth((short) 15);
        sheet.setColumnWidth((short) 0, (short) (11 * 512));
        sheet.setColumnWidth((short) 1, (short) (8 * 512));
        sheet.setColumnWidth((short) 2, (short) (8 * 512));
        sheet.setColumnWidth((short) 3, (short) (11 * 512));
        sheet.setColumnWidth((short) 4, (short) (11 * 512));
        sheet.setColumnWidth((short) 5, (short) (4 * 512));
        sheet.setColumnWidth((short) 6, (short) (8 * 512));
        sheet.setColumnWidth((short) 7, (short) (11 * 512));
        sheet.setColumnWidth((short) 8, (short) (11 * 512));
        sheet.setColumnWidth((short) 9, (short) (8 * 512));
        sheet.setColumnWidth((short) 10, (short) (8 * 512));
        sheet.setColumnWidth((short) 11, (short) (14 * 512));
        sheet.setColumnWidth((short) 12, (short) (16 * 512));
        sheet.setColumnWidth((short) 13, (short) (11 * 512));
        sheet.setColumnWidth((short) 14, (short) (8 * 512));
        sheet.setColumnWidth((short) 15, (short) (8 * 512));
        //第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
        HSSFRow row = sheet.createRow((int) 0);
        row.setHeightInPoints(36);
        //第四步，创建单元格，并设置值表头  设置表头居中
        HSSFCellStyle titleStyle = poiUtil.createTitleHSSFCellStyle(wb);
        HSSFCell titleCell = row.createCell((short) 0);
        titleCell.setCellStyle(titleStyle);
        titleCell.setEncoding(HSSFCell.ENCODING_UTF_16);
        titleCell.setCellValue("采购明细导出汇总表");
        // 四个参数分别是：起始行，起始列，结束行，结束列
        sheet.addMergedRegion(new Region(0, (short) 0, 0, (short) 14));
        row = sheet.createRow((int) 1);
        row.setHeightInPoints(21);
        //生成第一行数据
        HSSFCell htbm = row.createCell((short) 0);
        htbm.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        htbm.setEncoding(HSSFCell.ENCODING_UTF_16);
        htbm.setCellValue("采购单号");
        HSSFCell oldwzcode = row.createCell((short) 1);
        oldwzcode.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        oldwzcode.setEncoding(HSSFCell.ENCODING_UTF_16);
        oldwzcode.setCellValue("老物资编码");
        HSSFCell wzcode = row.createCell((short) 2);
        wzcode.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        wzcode.setEncoding(HSSFCell.ENCODING_UTF_16);
        wzcode.setCellValue("物资编码");
        HSSFCell wzname = row.createCell((short) 3);
        wzname.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        wzname.setEncoding(HSSFCell.ENCODING_UTF_16);
        wzname.setCellValue("品名");
        HSSFCell wzggxh = row.createCell((short) 4);
        wzggxh.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        wzggxh.setEncoding(HSSFCell.ENCODING_UTF_16);
        wzggxh.setCellValue("规格");
        HSSFCell wzdw = row.createCell((short) 5);
        wzdw.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        wzdw.setEncoding(HSSFCell.ENCODING_UTF_16);
        wzdw.setCellValue("单位");
        HSSFCell wzth = row.createCell((short) 6);
        wzth.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        wzth.setEncoding(HSSFCell.ENCODING_UTF_16);
        wzth.setCellValue("图号");
        HSSFCell sbsl = row.createCell((short) 7);
        sbsl.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        sbsl.setEncoding(HSSFCell.ENCODING_UTF_16);
        sbsl.setCellValue("采购数量");
        HSSFCell rksl = row.createCell((short) 8);
        rksl.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        rksl.setEncoding(HSSFCell.ENCODING_UTF_16);
        rksl.setCellValue("入库数量");
        HSSFCell hsj = row.createCell((short) 9);
        hsj.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        hsj.setEncoding(HSSFCell.ENCODING_UTF_16);
        hsj.setCellValue("含税单");
        HSSFCell bhsj = row.createCell((short) 10);
        bhsj.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        bhsj.setEncoding(HSSFCell.ENCODING_UTF_16);
        bhsj.setCellValue("不含税单价");
        HSSFCell hse = row.createCell((short) 11);
        hse.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        hse.setEncoding(HSSFCell.ENCODING_UTF_16);
        hse.setCellValue("采购总金额");
        HSSFCell gys = row.createCell((short) 12);
        gys.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        gys.setEncoding(HSSFCell.ENCODING_UTF_16);
        gys.setCellValue("供应商");
        HSSFCell ck = row.createCell((short) 13);
        ck.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        ck.setEncoding(HSSFCell.ENCODING_UTF_16);
        ck.setCellValue("仓库");
        HSSFCell gsmc = row.createCell((short) 14);
        gsmc.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        gsmc.setEncoding(HSSFCell.ENCODING_UTF_16);
        gsmc.setCellValue("公司名称");
        HSSFCell bmmc = row.createCell((short) 15);
        bmmc.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        bmmc.setEncoding(HSSFCell.ENCODING_UTF_16);
        bmmc.setCellValue("部门名称");
        //表体部分
        for (int i = 2; i < cgmxList.size() + 2; i++) {
            row = sheet.createRow(i);
            row.setHeightInPoints(19);
            htbm = row.createCell((short) 0);
//            htbm.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            htbm.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("cgdh")) {
                htbm.setCellValue(cgmxList.get(i - 2).get("cgdh").toString());
            }

            oldwzcode = row.createCell((short) 1);
//            oldwzcode.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            oldwzcode.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("gg.oldcode")) {
                oldwzcode.setCellValue(cgmxList.get(i - 2).get("gg.oldcode").toString());
            }

            wzcode = row.createCell((short) 2);
//            wzcode.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            wzcode.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("gg.code")) {
                wzcode.setCellValue(cgmxList.get(i - 2).get("gg.code").toString());
            }

            wzname = row.createCell((short) 3);
//            wzname.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            wzname.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("gg.name")) {
                wzname.setCellValue(cgmxList.get(i - 2).get("gg.name").toString());
            }

            wzggxh = row.createCell((short) 4);
//            wzggxh.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            wzggxh.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("gg.ggxh")) {
                wzggxh.setCellValue(cgmxList.get(i - 2).get("gg.ggxh").toString());
            }

            wzdw = row.createCell((short) 5);
//            wzdw.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            wzdw.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("gg.dw")) {
                wzdw.setCellValue(cgmxList.get(i - 2).get("gg.dw").toString());
            }

            wzth = row.createCell((short) 6);
//            wzth.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            wzth.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("gg.th")) {
                wzth.setCellValue(cgmxList.get(i - 2).get("gg.th").toString());
            }

            sbsl = row.createCell((short) 7);
//            sbsl.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            sbsl.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("sbsl")) {
                if (cgmxList.get(i - 2).get("sbsl") instanceof Number) {
                    sbsl.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                }
                BigDecimal bigDecimal_sbsl = new BigDecimal(cgmxList.get(i - 2).get("sbsl").toString()).setScale(4, BigDecimal.ROUND_HALF_UP);
                sbsl.setCellValue(bigDecimal_sbsl.doubleValue());
            }

            rksl = row.createCell((short) 8);
//            sbsl.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            rksl.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("rksl")) {
                if (cgmxList.get(i - 2).get("rksl") instanceof Number) {
                    rksl.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                }
                BigDecimal bigDecimal_rksl = new BigDecimal(cgmxList.get(i - 2).get("rksl").toString()).setScale(4, BigDecimal.ROUND_HALF_UP);
                rksl.setCellValue(bigDecimal_rksl.doubleValue());
            }

            hsj = row.createCell((short) 9);
//            hsj.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            hsj.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("hsj")) {
                if (cgmxList.get(i - 2).get("hsj") instanceof Number) {
                    hsj.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                }
                BigDecimal bigDecimal_hsj = new BigDecimal(cgmxList.get(i - 2).get("hsj").toString()).setScale(4, BigDecimal.ROUND_HALF_UP);
                hsj.setCellValue(bigDecimal_hsj.doubleValue());
            }

            bhsj = row.createCell((short) 10);
//            bhsj.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            bhsj.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("bhsj")) {
                if (cgmxList.get(i - 2).get("bhsj") instanceof Number) {
                    bhsj.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                }
                BigDecimal bigDecimal_bhsj = new BigDecimal(cgmxList.get(i - 2).get("bhsj").toString()).setScale(4, BigDecimal.ROUND_HALF_UP);
                bhsj.setCellValue(bigDecimal_bhsj.doubleValue());
            }

            hse = row.createCell((short) 11);
//            hse.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            hse.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("hse")) {
                if (cgmxList.get(i - 2).get("hse") instanceof Number) {
                    hse.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                }
                BigDecimal bigDecimal_hse = new BigDecimal(cgmxList.get(i - 2).get("hse").toString()).setScale(4, BigDecimal.ROUND_HALF_UP);
                hse.setCellValue(bigDecimal_hse.doubleValue());
            }

            gys = row.createCell((short) 12);
//            gys.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            gys.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("gysJc")) {
                gys.setCellValue(cgmxList.get(i - 2).get("gysJc").toString());
            }

            ck = row.createCell((short) 13);
//            ck.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            ck.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("ckmc")) {
                ck.setCellValue(cgmxList.get(i - 2).get("ckmc").toString());
            }

            gsmc = row.createCell((short) 14);
//            gsmc.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            gsmc.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("sbgsJc")) {
                gsmc.setCellValue(cgmxList.get(i - 2).get("sbgsJc").toString());
            }

            bmmc = row.createCell((short) 15);
//            bmmc.setCellStyle(poiUtil.createContentHSSFCellStyle(wb));
            bmmc.setEncoding(HSSFCell.ENCODING_UTF_16);
            if (null != cgmxList.get(i - 2).get("sbbmQc")) {
                bmmc.setCellValue(cgmxList.get(i - 2).get("sbbmQc").toString());
            }
        }

        List<Map> sumList = this.cgdmxDao.findSumCgdmx(cgdh, gysId, ckId, code, name, ggxh, sbgsId, sbbmId, zt, fhrqStart, fhrqEnd);
        Double total_sbsl = 0d;
        Double total_rksl = 0d;
        Double total_hse = 0d;
        if (sumList.size() != 0) {
            for (Map map : sumList) {
                total_sbsl += Double.valueOf((map.get("sumsl") == null ? 0d : map.get("sumsl")).toString());
                total_rksl += Double.valueOf((map.get("sumrksl") == null ? 0d : map.get("sumrksl")).toString());
                total_hse += Double.valueOf((map.get("sumhse") == null ? 0d : map.get("sumhse")).toString());
            }
        }
        BigDecimal bigDecimal_total_sbsl = new BigDecimal(total_sbsl).setScale(4, BigDecimal.ROUND_HALF_UP);
        BigDecimal bigDecimal_total_rksl = new BigDecimal(total_rksl).setScale(4, BigDecimal.ROUND_HALF_UP);
        BigDecimal bigDecimal_total_hse = new BigDecimal(total_hse).setScale(4, BigDecimal.ROUND_HALF_UP);
        //合计
        row = sheet.createRow(cgmxList.size() + 2);
        row.setHeightInPoints(19);
        HSSFCell total_hj = row.createCell((short) 0);
        total_hj.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_hj.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_hj.setCellValue("合计：");
        HSSFCell total_oldwzcode = row.createCell((short) 1);
        total_oldwzcode.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_oldwzcode.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_oldwzcode.setCellValue("");
        HSSFCell total_wzcode = row.createCell((short) 2);
        total_wzcode.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_wzcode.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_wzcode.setCellValue("");
        HSSFCell total_wzname = row.createCell((short) 3);
        total_wzname.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_wzname.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_wzname.setCellValue("");
        HSSFCell total_wzggxh = row.createCell((short) 4);
        total_wzggxh.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_wzggxh.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_wzggxh.setCellValue("");
        HSSFCell total_wzdw = row.createCell((short) 5);
        total_wzdw.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_wzdw.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_wzdw.setCellValue("");
        HSSFCell total_wzth = row.createCell((short) 6);
        total_wzth.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_wzth.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_wzth.setCellValue("");
        HSSFCell total_cgsl = row.createCell((short) 7);
        total_cgsl.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_cgsl.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_cgsl.setCellValue(bigDecimal_total_sbsl.toString());
        HSSFCell total_cgrksl = row.createCell((short) 8);
        total_cgrksl.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_cgrksl.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_cgrksl.setCellValue(bigDecimal_total_rksl.toString());
        HSSFCell total_hsj = row.createCell((short) 9);
        total_hsj.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_hsj.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_hsj.setCellValue("");
        HSSFCell total_bhsj = row.createCell((short) 10);
        total_bhsj.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_bhsj.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_bhsj.setCellValue("");
        HSSFCell total_cgje = row.createCell((short) 11);
        total_cgje.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_cgje.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_cgje.setCellValue(bigDecimal_total_hse.toString());
        HSSFCell total_gys = row.createCell((short) 12);
        total_gys.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_gys.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_gys.setCellValue("");
        HSSFCell total_ck = row.createCell((short) 13);
        total_ck.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_ck.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_ck.setCellValue("");
        HSSFCell total_gsmc = row.createCell((short) 14);
        total_gsmc.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_gsmc.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_gsmc.setCellValue("");
        HSSFCell total_bmmc = row.createCell((short) 15);
        total_bmmc.setCellStyle(poiUtil.createHeaderHSSFCellStyle(wb));
        total_bmmc.setEncoding(HSSFCell.ENCODING_UTF_16);
        total_bmmc.setCellValue("");

        try {
            response.setContentType("application/x-download");
            String filedisplay = new String(("采购明细汇总表.xls").getBytes("gb2312"), "iso8859-1");
            response.addHeader("Content-Disposition", "attachment;filename=" + filedisplay);
            wb.write(response.getOutputStream());
            response.getOutputStream().close();
        } catch (Exception e) {
            e.printStackTrace();
            renderText("位置异常，导出失败" + e.getMessage());
        }
        return null;
    }

    //采购明细标签打印  (铁运入库标签)
    @Action("tag_export")
    public String cgmxTagExport() {
        List<Map> cgdmxs = cgdmxDao.finCgdmxs(cgdmxIds);
        HSSFWorkbook excel = new HSSFWorkbook();
        POIUtil poiUtil = new POIUtil(excel);
        HSSFCellStyle cellStyleCenter = poiUtil.createContent3HSSFCellStyle(excel);
        HSSFCellStyle cellStyleLeft = poiUtil.createContent4HSSFCellStyle(excel);
        HSSFSheet sheet = excel.createSheet();
        excel.setSheetName(0, "库架标签", HSSFWorkbook.ENCODING_UTF_16);
        sheet.setDefaultColumnWidth((short) 6);
        sheet.setColumnWidth((short) 0, (short) (1450));
        sheet.setColumnWidth((short) 1, (short) (3900));
        sheet.setColumnWidth((short) 2, (short) (1450));
        sheet.setColumnWidth((short) 3, (short) (1450));
        sheet.setColumnWidth((short) 4, (short) (4040));

        sheet.setColumnWidth((short) 5, (short) (0.5 * 512));

        sheet.setColumnWidth((short) 6, (short) (1450));
        sheet.setColumnWidth((short) 7, (short) (3900));
        sheet.setColumnWidth((short) 8, (short) (1450));
        sheet.setColumnWidth((short) 9, (short) (1450));
        sheet.setColumnWidth((short) 10, (short) (4040));

        for (int i = 0, j = 0; i < cgdmxs.size(); i = i + 2, j++) {
            HSSFRow row0 = sheet.createRow(0 + (j * 5));
            row0.setHeight((short) 480);
            sheet.addMergedRegion(new Region((short) 0 + (j * 5), (short) 0, (short) 0 + (j * 5), (short) 4));
            sheet.addMergedRegion(new Region((short) 0 + (j * 5), (short) 6, (short) 0 + (j * 5), (short) 10));

            HSSFRow row1 = sheet.createRow(1 + (j * 5));
            row1.setHeight((short) 480);
            sheet.addMergedRegion(new Region((short) 1 + (j * 5), (short) 1, (short) 1 + (j * 5), (short) 4));
            sheet.addMergedRegion(new Region((short) 1 + (j * 5), (short) 7, (short) 1 + (j * 5), (short) 10));

            HSSFRow row2 = sheet.createRow(2 + (j * 5));
            row2.setHeight((short) 480);
            sheet.addMergedRegion(new Region((short) 2 + (j * 5), (short) 3, (short) 2 + (j * 5), (short) 4));
            sheet.addMergedRegion(new Region((short) 2 + (j * 5), (short) 9, (short) 2 + (j * 5), (short) 10));
            HSSFRow row3 = sheet.createRow(3 + (j * 5));
            row3.setHeight((short) 480);
            HSSFRow row4 = sheet.createRow(4 + (j * 5));
            row4.setHeight((short) 400);

            if (i < cgdmxs.size()) {
                HSSFCell cell00 = row0.createCell((short) 0);
                row0.createCell((short) 1).setCellStyle(cellStyleCenter);
                row0.createCell((short) 2).setCellStyle(cellStyleCenter);
                row0.createCell((short) 3).setCellStyle(cellStyleCenter);
                row0.createCell((short) 4).setCellStyle(cellStyleCenter);
                cell00.setCellStyle(cellStyleCenter);
                cell00.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell00.setCellValue("库      架      层      位");
                HSSFCell cell10 = row1.createCell((short) 0);
                cell10.setCellStyle(cellStyleCenter);
                cell10.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell10.setCellValue("名称");
                HSSFCell cell11 = row1.createCell((short) 1);
                cell11.setCellStyle(cellStyleCenter);
                row1.createCell((short) 4).setCellStyle(cellStyleCenter);
                cell11.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell11.setCellValue(cgdmxs.get(i).get("NAME").toString());
                HSSFCell cell20 = row2.createCell((short) 0);
                cell20.setCellStyle(cellStyleCenter);
                cell20.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell20.setCellValue("编码");
                HSSFCell cell21 = row2.createCell((short) 1);
                cell21.setCellStyle(cellStyleCenter);
                cell21.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell21.setCellValue(cgdmxs.get(i).get("CODE").toString());
                HSSFCell cell22 = row2.createCell((short) 2);
                cell22.setCellStyle(cellStyleLeft);
                cell22.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell22.setCellValue("规格");
                HSSFCell cell23 = row2.createCell((short) 3);
                cell23.setCellStyle(cellStyleCenter);
                row2.createCell((short) 4).setCellStyle(cellStyleCenter);
                cell23.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell23.setCellValue(cgdmxs.get(i).get("GGXH").toString());

                HSSFCell cell30 = row3.createCell((short) 0);
                cell30.setCellStyle(cellStyleCenter);
                cell30.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell30.setCellValue("单价");
                HSSFCell cell31 = row3.createCell((short) 1);
                cell31.setCellStyle(cellStyleCenter);
                cell31.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell31.setCellValue(cgdmxs.get(i).get("WSDJ").toString());
                HSSFCell cell32 = row3.createCell((short) 2);
                cell32.setCellStyle(cellStyleCenter);
                cell32.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell32.setCellValue("单位");
                HSSFCell cell33 = row3.createCell((short) 3);
                cell33.setCellStyle(cellStyleCenter);
                cell33.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell33.setCellValue(cgdmxs.get(i).get("DW").toString());
                HSSFCell cell34 = row3.createCell((short) 4);
                cell34.setCellStyle(cellStyleLeft);
                cell34.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell34.setCellValue("备注:");
            }
            //分割
            HSSFCell cell06 = row0.createCell((short) 6);

            if (i + 1 < cgdmxs.size()) {
                row0.createCell((short) 7).setCellStyle(cellStyleCenter);
                row0.createCell((short) 8).setCellStyle(cellStyleCenter);
                row0.createCell((short) 9).setCellStyle(cellStyleCenter);
                row0.createCell((short) 10).setCellStyle(cellStyleCenter);
                cell06.setCellStyle(cellStyleCenter);
                cell06.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell06.setCellValue("库      架      层      位");
                HSSFCell cell16 = row1.createCell((short) 6);
                cell16.setCellStyle(cellStyleCenter);
                cell16.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell16.setCellValue("名称");
                HSSFCell cell17 = row1.createCell((short) 7);
                cell17.setCellStyle(cellStyleCenter);
                row1.createCell((short) 10).setCellStyle(cellStyleCenter);
                cell17.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell17.setCellValue(cgdmxs.get(i + 1).get("NAME").toString());
                HSSFCell cell26 = row2.createCell((short) 6);
                cell26.setCellStyle(cellStyleCenter);
                cell26.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell26.setCellValue("编码");
                HSSFCell cell27 = row2.createCell((short) 7);
                cell27.setCellStyle(cellStyleCenter);
                cell27.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell27.setCellValue(cgdmxs.get(i + 1).get("CODE").toString());
                HSSFCell cell28 = row2.createCell((short) 8);
                cell28.setCellStyle(cellStyleLeft);
                cell28.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell28.setCellValue("规格");
                HSSFCell cell29 = row2.createCell((short) 9);
                cell29.setCellStyle(cellStyleCenter);
                row2.createCell((short) 10).setCellStyle(cellStyleCenter);
                cell29.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell29.setCellValue(cgdmxs.get(i + 1).get("GGXH").toString());
                HSSFCell cell36 = row3.createCell((short) 6);
                cell36.setCellStyle(cellStyleCenter);
                cell36.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell36.setCellValue("单价");
                HSSFCell cell37 = row3.createCell((short) 7);
                cell37.setCellStyle(cellStyleCenter);
                cell37.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell37.setCellValue(cgdmxs.get(i + 1).get("WSDJ").toString());
                HSSFCell cell38 = row3.createCell((short) 8);
                cell38.setCellStyle(cellStyleCenter);
                cell38.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell38.setCellValue("单位");
                HSSFCell cell39 = row3.createCell((short) 9);
                cell39.setCellStyle(cellStyleCenter);
                cell39.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell39.setCellValue(cgdmxs.get(i + 1).get("DW").toString());
                HSSFCell cell310 = row3.createCell((short) 10);
                cell310.setCellStyle(cellStyleLeft);
                cell310.setEncoding(HSSFCell.ENCODING_UTF_16);
                cell310.setCellValue("备注:");
            }

        }
        try {
            response.setContentType("application/x-download");
            String filedisplay = new String(("采购明细汇总表.xls").getBytes("gb2312"), "iso8859-1");
            response.addHeader("Content-Disposition", "attachment;filename=" + filedisplay);
            excel.write(response.getOutputStream());
            response.getOutputStream().close();
        } catch (Exception e) {
            e.printStackTrace();
            renderText("位置异常，导出失败" + e.getMessage());
        }
        return null;
    }

    //=========getter===setter====================

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public Long getGysId() {
        return gysId;
    }

    public void setGysId(Long gysId) {
        this.gysId = gysId;
    }

    public String getGysJc() {
        return gysJc;
    }

    public void setGysJc(String gysJc) {
        this.gysJc = gysJc;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGgxh() {
        return ggxh;
    }

    public void setGgxh(String ggxh) {
        this.ggxh = ggxh;
    }

    public Long getSbgsId() {
        return sbgsId;
    }

    public void setSbgsId(Long sbgsId) {
        this.sbgsId = sbgsId;
    }

    public Long getSbbmId() {
        return sbbmId;
    }

    public void setSbbmId(Long sbbmId) {
        this.sbbmId = sbbmId;
    }

    public String getCgdh() {
        return cgdh;
    }

    public void setCgdh(String cgdh) {
        this.cgdh = cgdh;
    }


    public Long getCkId() {
        return ckId;
    }

    public void setCkId(Long ckId) {
        this.ckId = ckId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public List<Gncz> getGnczList() {
        return gnczList;
    }

    public void setGnczList(List<Gncz> gnczList) {
        this.gnczList = gnczList;
    }

    public String getZt() {
        return zt;
    }

    public void setZt(String zt) {
        this.zt = zt;
    }

    public Long[] getCgdmxIds() {
        return cgdmxIds;
    }

    public void setCgdmxIds(Long[] cgdmxIds) {
        this.cgdmxIds = cgdmxIds;
    }

    public Date getCurrentTime() {
        return CurrentTime;
    }

    public void setCurrentTime(Date currentTime) {
        CurrentTime = currentTime;
    }

    public Date getFhrqStart() {
        return fhrqStart;
    }

    public void setFhrqStart(Date fhrqStart) {
        this.fhrqStart = fhrqStart;
    }

    public Date getFhrqEnd() {
        return fhrqEnd;
    }

    public void setFhrqEnd(Date fhrqEnd) {
        this.fhrqEnd = fhrqEnd;
    }

    @Autowired
    public void setCgdmxService(CgdmxService cgdmxService) {
        this.cgdmxService = cgdmxService;
    }

    @Autowired
    public void setCgdmxDao(CgdmxDao cgdmxDao) {
        this.cgdmxDao = cgdmxDao;
    }

    @Autowired
    public void setGnczService(GnczService gnczService) {
        this.gnczService = gnczService;
    }
}
